#include "Observer.h"

void Publisher::Subscribe(IObserver* observer)
{
	list_Observer_.push_back(observer);
}

void Publisher::UnSubscribe(IObserver* observer)
{
	list_Observer_.remove(observer);
}

void Publisher::Notify()
{
	std::cout << "There Are " << list_Observer_.size() << "Observers In The List";

	std::list<IObserver*>::iterator iterator = list_Observer_.begin();
	while (iterator != list_Observer_.end())
	{
		(*iterator)->Update(newspaper_);
		++iterator;
	}
}

void Publisher::Publish(std::string newspapers)
{
	this->newspaper_ = newspapers;
	Notify();
}

void Observer::Update(const std::string& newspapers) const
{
	std::cout << "Observer " << this->number_ << ": A New Newspaper Is Avaliable-->" << newspapers << std::endl;
}

void Observer::RemoveMeFromTheList()
{
	subject_->UnSubscribe(this);
	std::cout << "Observer " << this->number_ << " Removed From The List" << std::endl;
}
